load("@bazel_skylib//lib:selects.bzl", "selects")
load("//bazel:skia_rules.bzl", "exports_files_legacy", "skia_cc_library")

licenses(["notice"])

exports_files_legacy()

selects.config_setting_group(
    name = "use_harfbuzz_shaper",
    match_all = [
        "//bazel/common_config_settings:use_harfbuzz_true",
    ],
)

# TODO(kjlubick,bungeman) delete skshaper (uses legacy non-modular build)

skia_cc_library(
    name = "legacy_skshaper",
    srcs = ["//modules/skshaper/src:srcs"],
    hdrs = ["//modules/skshaper/include:hdrs"],
    defines = [
        "SK_SHAPER_UNICODE_AVAILABLE",
        "SK_SHAPER_PRIMITIVE_AVAILABLE",
    ] + select({
        ":use_harfbuzz_shaper": ["SK_SHAPER_HARFBUZZ_AVAILABLE"],
        "//conditions:default": [],
    }),
    local_defines = ["SKSHAPER_IMPLEMENTATION=1"],
    visibility = ["//:__subpackages__"],
    # TODO(kjlubick,bungeman) someday implementation_deps will be available
    #implementation_deps = ["//modules/skunicode"] + select({
    #    ":use_harfbuzz_shaper": [
    #        "@harfbuzz",
    #    ],
    #    "//conditions:default": [],
    #}),
    #deps = ["//:skia_internal"]
    deps = [
        "//:skia_internal",
        "//modules/skunicode:legacy_skunicode",
    ] + select({
        ":use_harfbuzz_shaper": [
            "@harfbuzz",
        ],
        "//conditions:default": [],
    }),
)

skia_cc_library(
    name = "skshaper_core",
    srcs = [
        "//modules/skshaper/src:core_srcs",
    ],
    hdrs = ["//modules/skshaper/include:core_hdrs"],
    defines = ["SK_DISABLE_LEGACY_SKSHAPER_FUNCTIONS"],
    features = ["layering_check"],
    local_defines = ["SKSHAPER_IMPLEMENTATION=1"],
    visibility = [
        "//:__subpackages__",
    ],
    deps = [
        "//:core",
        "//src/base",
        "//src/core:core_priv",
    ],
)

skia_cc_library(
    name = "skshaper_harfbuzz",
    srcs = [
        "//modules/skshaper/src:harfbuzz_srcs",
    ],
    hdrs = [
        "//modules/skshaper/include:core_hdrs",
        "//modules/skshaper/include:harfbuzz_hdrs",
    ],
    defines = [
        "SK_SHAPER_HARFBUZZ_AVAILABLE",
        "SK_DISABLE_LEGACY_SKSHAPER_FUNCTIONS",
    ],
    features = ["layering_check"],
    local_defines = ["SKSHAPER_IMPLEMENTATION=1"],
    visibility = [
        "//:__subpackages__",
    ],
    deps = [
        ":skshaper_core",
        "//:core",
        "//modules/skunicode:skunicode_icu",  # TODO(kjlubick) make this depend on skunicode_core
        "//src/base",
        "//src/core:core_priv",
        "@harfbuzz",
    ],
)

skia_cc_library(
    name = "skshaper_unicode",
    srcs = [
        "//modules/skshaper/src:skunicode_srcs",
    ],
    hdrs = [
        "//modules/skshaper/include:core_hdrs",
        "//modules/skshaper/include:skunicode_hdrs",
    ],
    defines = [
        "SK_SHAPER_UNICODE_AVAILABLE",
        "SK_DISABLE_LEGACY_SKSHAPER_FUNCTIONS",
    ],
    features = ["layering_check"],
    local_defines = ["SKSHAPER_IMPLEMENTATION=1"],
    visibility = [
        "//:__subpackages__",
    ],
    deps = [
        ":skshaper_core",
        "//:core",
        "//modules/skunicode:skunicode_icu",  # TODO(kjlubick) make this depend on skunicode_core
        "//src/base",
        "//src/core:core_priv",
    ],
)
